// component/FStop/fstop.js
const app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    multipleSlots: true
  },

  properties: {
    // 弹窗标题    
    manName: {            // 属性名
      type: String,     // 类型（必填），目前接受的类型包括：String, Number, Boolean, Object, Array, null（表示任意类型）
      value: '李慧'     // 属性初始值（可选），如果未指定则会根据类型选择一个
    },
    avatarUrl: {
      type: String,
      value: "../../img/man.png"
    },
    projectNum: {
      type: String,
      value: '0'
    },
    serviceNum: {
      type: String,
      value: '0'
    },
    payNum: {
      type: String,
      value: '0'
    },
    departmentList: {
      type: Array,
      value: new Array()
    },
    isHidden: {
      type: Boolean,
      value: false
    },//是否显示tab切换
  },

  /**
   * 组件的初始数据
   */
  data: {
    isSelected: false,
    showDepartment: false,
    job: '非诉项目',
    flagName: "nonLitigation",
    menuTab: "project",//项目("project"),//服务动态("service"),收支记录("pay")
    projectSlt: true,
    serviceSlt: false,
    paySlt: false,
    ShareDocSlt: false
  },

  /**
   * 组件的方法列表
   */
  methods: {
    avatartap: function () {
      wx.showActionSheet({
        itemList: ['退出登录'],
        success: function (res) {
          console.log(res.tapIndex)
          if (res.tapIndex == 0) {
            wx.clearStorageSync();
            app.globalData.userInfo = null;
            app.globalData.loginUserInfo = '';
            wx.redirectTo({
              url: '../../index/index'
            })
          }
        },
        fail: function (res) {
          console.log(res.errMsg)
        }
      })
    },
    departmentCon: function () {
      this.setData({
        showDepartment: false,
      })
    },
    goproject: function () {
      this.setData({
        projectSlt: true,
        serviceSlt: false,
        paySlt: false,
        ShareDocSlt: false,
      });
      //触发我的关注
      this.triggerEvent("goproject", this.data.flagName + "|" + "project");
    },
    goservice: function () {
      this.setData({
        projectSlt: false,
        serviceSlt: true,
        paySlt: false,
        ShareDocSlt: false,
      });
      //触发我的关注
      this.triggerEvent("goservice", this.data.flagName + "|" + "service");
    },
    gopay: function () {
      this.setData({
        projectSlt: false,
        serviceSlt: false,
        paySlt: true,
        ShareDocSlt: false,
      });
      //触发我的关注
      this.triggerEvent("gopay", this.data.flagName + "|" + "pay");
    },
    //去文档库
    goShareDoc: function () {
      this.setData({
        projectSlt: false,
        serviceSlt: false,
        paySlt: false,
        ShareDocSlt: true,
      });
      //触发我的关注
      this.triggerEvent("goShareDoc", this.data.flagName + "|" + "ShareDoc");
    },
    selectTask(e) {
      let array = this.data.taskList;
      let index = e.currentTarget.dataset.index;
      for (let i = 0; i < array.length; i++) {
        array[i].slt = ''
      }
      array[index].slt = 'border-bottom:1px solid #222';

      this.setData({
        taskList: array
      })
    },
    isShowDepartment() {
      let jobArray = this.data.departmentList;
      let jobSlt = this.data.job;
      if (jobArray.length <= 1) {
        return
      }
      if (!this.data.showDepartment) {
        for (let i = 0; i < jobArray.length; i++) {
          jobArray[i].selected = false;
          if (jobArray[i].name == jobSlt) {
            jobArray[i].selected = true;
            // console.log('===========一样了')
          }
        }
        this.setData({
          showDepartment: true,
          departmentList: jobArray
        })
      } else {
        this.setData({
          showDepartment: false
        })
      }
    },

    //选中部门选择
    selectJob(e) {
      app.globalData.listRefresh={};
      let jobArray = this.data.departmentList;
      let index = e.currentTarget.dataset.index;
      let flagName = jobArray[index].flagName;
      wx.setStorageSync("flagName", flagName);
      if (flagName == 'lawsuitInvest') {
        this.setData({
          showDepartment: false
        })
        wx.redirectTo({
          url: '../../SuSong/ssIndex/ssIndex?flagName=' + flagName
        })
      }else if (flagName == "lawsuit" || flagName == 'enforce') {
        this.setData({
          showDepartment: false
        })
        wx.redirectTo({
          url: '../../syIndex/syIndex?flagName=' + flagName
        })
      } else if (flagName == "caseTrack") {
        this.setData({
          showDepartment: false
        })
        wx.redirectTo({
          url: '../../Case/caseIndex/caseIndex?flagName=' + flagName
        })
      }else {
        this.setData({
          job: jobArray[index].name,
          flagName: flagName,
          showDepartment: false,
          toDoNumSlt: true,
          attentionNumSlt: false,
          dynamicStateSlt: false,
        })
        //触发取消回调
        this.triggerEvent("selectDepart", flagName)
      }
    }
  }
})